'use client';

import React from 'react';
import { Table, Button } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import Link from 'next/link';

// 定义数据类型
interface DataType {
  key: string;
  name: string;
  age: number;
  address: string;
  tags: string[];
}

// 静态数据
const data: DataType[] = [
  {
    key: '1',
    name: '张三',
    age: 32,
    address: '北京市朝阳区',
    tags: ['开发', '前端'],
  },
  {
    key: '2',
    name: '李四',
    age: 42,
    address: '上海市浦东新区',
    tags: ['设计', 'UI'],
  },
  {
    key: '3',
    name: '王五',
    age: 28,
    address: '广州市天河区',
    tags: ['产品', '经理'],
  },
  {
    key: '4',
    name: '赵六',
    age: 35,
    address: '深圳市南山区',
    tags: ['测试', 'QA'],
  },
  {
    key: '5',
    name: '钱七',
    age: 30,
    address: '杭州市西湖区',
    tags: ['运维', 'DevOps'],
  },
];

// 定义表格列
const columns: ColumnsType<DataType> = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
    sorter: (a, b) => a.age - b.age,
  },
  {
    title: '地址',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title: '标签',
    key: 'tags',
    dataIndex: 'tags',
    render: (_, { tags }) => (
      <>
        {tags.map(tag => (
          <span key={tag} className="bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-xs mr-1">
            {tag}
          </span>
        ))}
      </>
    ),
  },
];

export default function TablePage() {
  return (
    <div className="p-8">
      <div className="max-w-6xl mx-auto">
        <div className="flex justify-between items-center mb-6">
          <h1 className="text-3xl font-bold">用户数据表格</h1>
          <Link href="/">
            <Button type="primary">返回首页</Button>
          </Link>
        </div>
        
        <div  style={{ width: "100%", height: "100%" }}>
          <Table 
            columns={columns} 
            dataSource={data} 
            pagination={{ pageSize: 10 }}
            className="w-full"
          />
        </div>
      </div>
    </div>
  );
} 